package com.duobaoyu.dby.supply.biz.client.resource.impl;

import com.duobaoyu.dby.common.core.constant.SecurityConstants;
import com.duobaoyu.dby.common.core.constant.ServiceNameConstants;
import com.duobaoyu.dby.common.core.constant.StringPool;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.resource.admin.feign.RemoteResourceRiskControlAdminService;
import com.duobaoyu.dby.resource.common.admin.dto.config.ModifyRiskStrategyConfigDTO;
import com.duobaoyu.dby.resource.common.admin.to.config.RiskStrategyConfigInfoTO;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceRiskControlAdminClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.RiskStrategyConfigDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.RiskStrategyConfigInfoVO;
import com.duobaoyu.dby.supply.biz.client.resource.converter.ResourceConverter;
import com.duobaoyu.dby.supply.biz.util.RemoteResultCheckUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName ResourceRiskControlAdminClientImpl
 * @createTime 15:02:00 2023/10/08
 */
@Component
@RequiredArgsConstructor
public class ResourceRiskControlAdminClientImpl implements ResourceRiskControlAdminClient {

    private final ResourceConverter resourceConverter;
    private final RemoteResourceRiskControlAdminService remoteResourceRiskControlAdminService;


    @Override
    public List<RiskStrategyConfigInfoVO> getRiskStrategyInfo() {
        R<List<RiskStrategyConfigInfoTO>> result = remoteResourceRiskControlAdminService.getRiskStrategyInfo(SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, StringPool.EMPTY);
        return resourceConverter.toRiskStrategyConfigInfoList(result.getData());
    }

    @Override
    public Boolean modifyRiskStrategy(RiskStrategyConfigDTO riskStrategyConfig) {
        ModifyRiskStrategyConfigDTO dto = resourceConverter.toModifyRiskStrategyConfig(riskStrategyConfig);
        R<Boolean> result = remoteResourceRiskControlAdminService.modifyRiskStrategy(dto, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, riskStrategyConfig);
        return result.getData();
    }
}
